package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Client {
    public static void main(String[] args) {
        DatagramSocket datagramSocket = null;
        try {
            //创建客户端
            datagramSocket = new DatagramSocket(7777);

            //创建发送的消息
            byte[] bytes = "测试客户端发送消息".getBytes();
            //封装数据包
            DatagramPacket datagramPacket = new DatagramPacket(bytes,bytes.length, InetAddress.getLocalHost(),8081);

            //发送数据
            datagramSocket.send(datagramPacket);
            System.out.println("数据发送结束---");
        }catch (Exception e){

        }finally {
            datagramSocket.close();
        }
    }
}
